import subprocess
import zipfile
import platform
from pathlib import Path

Path().parent.joinpath()

def enCrypt(filepath, passwd):
    '''创建加密压缩文件'''
    passwd = passwd.encode('utf-8')
    target = filepath.with_suffix('.zip')

    if platform.system() == 'Windows':
        command = ['rar', 'a', f'-p{passwd}', target, filepath]
        winrar = Path(f'C:\Program Files\WinRAR\WinRAR.exe')
        p = subprocess.Popen(command, executable=winrar)
        p.wait() # 登录命令执行
    else:
        command = ['zip', f'-P {passwd}', target, filepath]
        p = subprocess.Popen(command)
        p.wait() # 等待命令执行

